#include"SqList.h"
void SLInit(SL* ps) {
	assert(ps);
	ps->arr = NULL;
	ps->capacity = ps->size = 0;
}
void CapacityData(SL* ps) {
	if (ps->capacity == ps->size) {
		int newcapacity = ps->capacity== 0 ? 4 : ps->capacity * 2;
		SLDatatype* tmp = (SLDatatype*)realloc(ps->arr, sizeof(SLDatatype) * newcapacity);
		if (tmp == NULL) {
			perror("realloc fail");
		}
		ps->arr = tmp;
		ps->capacity = newcapacity;
	}
}
void SLBackPush(SL* ps, SLDatatype val) {
	assert(ps);
	CapacityData(ps);
	ps->arr[ps->size++] = val;
}
void SLBackPop(SL* ps) {
	assert(ps);
	assert(ps->size);
	ps->size--;
}
void SLFrontPush(SL* ps, SLDatatype val) {
	assert(ps);
	CapacityData(ps);
	for (int i = ps->size; i > 0; i--)
	{
		ps->arr[i]=ps->arr[i - 1];
	}
	ps->arr[0] = val;
	ps->size++;
}
void SLPrint(SL s) {
	for (int i = 0; i < s.size; i++) {
		printf("%d ", s.arr[i]);
	}
	printf("\n");
}
void SLDestroy(SL* ps) {
	assert(ps);
	free(ps->arr);
	ps->capacity = ps->size = 0;
}